package implementor;

import dao.FlatDao;
import dbhandelling.Crude;

import dto.Flat;

public class FlatImpl extends Crude implements FlatDao{

	String className=new Flat().getClass().getName();
	@Override
	public void add(Flat f) throws Exception {
		insert(f);
	}

	@Override
	public void update(Flat f) throws Exception {
		super.update(className, "bldgId", f.getBldgId()+"","autoIdFlat",f.getAutoIdFlat()+"");
		super.update(className, "flatName", f.getFlatName(),"autoIdFlat",f.getAutoIdFlat()+"");
		super.update(className, "state", f.getState()+"","autoIdFlat",f.getAutoIdFlat()+"");
		
	}

	@Override
	public void delete(Flat f) throws Exception {
		delete(className, "autoIdFlat",f.getAutoIdFlat()+"");
		
	}

	@Override
	public Flat retreive(String conditionField, String ConditionValue)
			throws Exception {
		Flat f=(Flat) super.retreive(className, conditionField, ConditionValue);
		return f;
	}

	@Override
	public Flat[] retreiveArray(String conditionField, String ConditionValue)
			throws Exception {
	
			Flat[] fl;
			Object[] obj=super.retreiveArrayOnCondition(className, conditionField, ConditionValue);
			fl=new Flat[obj.length];
			
			for(int i=0;i<fl.length;i++)
			{
				fl[i]=(Flat) obj[i];
			}
			
			return fl;
	}

	@Override
	public Flat[] retreiveAll() throws Exception {
		Flat[] fl;
		Object[] obj=super.retreiveAll(className);
		fl=new Flat[obj.length];
		
		for(int i=0;i<fl.length;i++)
		{
			fl[i]=(Flat) obj[i];
		}
		
		return fl;
	}

}
